package logic

import (
	"context"
	"errors"
	"video/mysql/model"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectionDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionDelLogic {
	return &CollectionDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 取消收藏
func (l *CollectionDelLogic) CollectionDel(in *videorpc.CollectionDelRequest) (*videorpc.CollectionDelResponse, error) {
	// todo: add your logic here and delete this line

	var collection model.Collection
	model.DB.Debug().Where("id = ?", in.CollectionId).Find(&collection)
	if collection.ID == 0 {
		return nil, errors.New("当前没有收藏视频,删除失败")
	}

	model.DB.Debug().Delete(&collection)

	return &videorpc.CollectionDelResponse{}, nil
}
